#include "Poco/Util/Application.h"

#include "cm_nat/WanP2PDaemon.h"
#include "cm_nat/WanP2PClient.h"

using namespace cm_nat;

int main2()
{
    Poco::Util::Application* p_app = new Poco::Util::Application;
    p_app->loadConfiguration("c:/test/test_case.xml");

    WanP2PDaemon p2p;
    p2p.setup("cmjabber_d", "123456", "jabber.org");

    ByteBufferPool bpool;
    bpool.setup(10, 200);

    std::string a;
    while(1)
    {
        std::cin>>a;
        
        if( a == "c"){
            ByteBuffer* p_buf = bpool.get(0);
            if( p_buf ){
                p_buf->increaseRef();
                p_buf->setLength(50);
                memset( (void*)(p_buf->Data()), 0, p_buf->Capacity() );
                p2p.send( p_buf );
            }
        }

    }
    return 0;
}


int main()
{
    Poco::Util::Application* p_app = new Poco::Util::Application;
    p_app->loadConfiguration("c:/test/test_case.xml");

    WanP2PClient p2p;
    p2p.setup("cmjabber_d", "123456", "jabber.org");

    ByteBufferPool bpool;
    bpool.setup(10, 200);

    std::string a;
    while(1)
    {
        std::cin>>a;
        if( a == "a"){
            p2p.createSession();
        }
        if( a == "b"){
            p2p.sendCandidate();
        }

        if( a == "s"){
            p2p.selectCandidate();
        }

        if( a == "c"){
            ByteBuffer* p_buf = bpool.get(0);
            if( p_buf ){
                p_buf->increaseRef();
                p_buf->setLength(50);
                memset( (void*)(p_buf->Data()), 0, p_buf->Capacity() );
                p2p.send( p_buf );
            }
        }

        if( a == "p"){
            p2p.xmppPing();
        }

    }
    return 0;
}
